﻿
///远程服务器Ajax数据操作
$.extend(Whale,
{
    Remote: {
        ///取远程服务器中单条数据
        GetEntity: function (settings) {
            var entity = null;
            $.when(
                $.ajax({
                    type: settings.type == "GET" ? "GET" : "POST",
                    url: settings.url,
                    data: settings.parameters,
                    async: settings.async == true,
                    success: function (response) {
                        if (response.Success)
                            return response;
                    }
                })).done(function (result) {
                    entity = result.Data;
                });
            return entity;
        },
        ///取远程服务器中的数据列表
        GetCollection: function (settings) {
            var lst = null;
            $.when(
                $.ajax({
                    type: settings.type == "GET" ? "GET" : "POST",
                    url: settings.url,
                    data: settings.parameters,
                    async: settings.async == true,
                    success: function (response) {
                        if (response.Success)
                            return response;
                    }
                })).done(function (result) {
                    lst = result;
                });
            return lst;
        },
        ///对远程服务器进行操作,并返回操作结果
        Operation: function (settings) {
            $.ajax({
                type: settings.type == "GET" ? "GET" : "POST",
                url: settings.url,
                data: settings.parameters,
                async: settings.async == true,
                success: function (response) {
                    if (response.Success)
                        settings.success(response.Data);
                    else
                        settings.error(response.Message);
                }
            })
        },
        ///取远程直接的返回值
        GetResult: function (settings) {
            var result = null;
            $.when(
                $.ajax({
                    type: settings.type == "GET" ? "GET" : "POST",
                    url: settings.url,
                    data: settings.parameters,
                    async: settings.async == true,
                    success: function (response) {
                        return response;
                    }
                })).done(function (ret) {
                    result = ret;
                });
            return result;
        }
    }
});